package Generic;

import java.util.ArrayList;
import java.util.Comparator;

/**
 * @author 王艺锡
 * @version 1.0
 */
@SuppressWarnings({"all"})
public class Exercise02 {
    public static void main(String[] args) {
        ArrayList<Employee> e = new ArrayList<>();
        e.add(new Employee("yx", 29000, new MyDate(2002, 03, 14)));
        e.add(new Employee("ly", 27000, new MyDate(2002, 03, 13)));
        e.add(new Employee("auren", 9000, new MyDate(1996, 05, 16)));
        e.add(new Employee("auren", 9000, new MyDate(1996, 05, 23)));
        e.sort(new Comparator<Employee>() {
            @Override
            public int compare(Employee o1, Employee o2) {
                int i = o1.getName().compareTo(o2.getName());
                if (i != 0) {
                    return i;
                } else {
                    //return MyDate.com(o1.getBirthday(), o2.getBirthday());
                    return o1.getBirthday().compareTo(o2.getBirthday());
                }
            }
        });
        System.out.println(e);
    }
}


class Employee {
    private String name;
    private double sal;
    private MyDate birthday;

    public Employee(String name, double sal, MyDate birthday) {
        this.name = name;
        this.sal = sal;
        this.birthday = birthday;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSal() {
        return sal;
    }

    public void setSal(double sal) {
        this.sal = sal;
    }

    public MyDate getBirthday() {
        return birthday;
    }

    public void setBirthday(MyDate birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return name + "_" + sal + "_" + birthday;
    }
}

class MyDate implements Comparable<MyDate>{
    private int year;
    private int month;
    private int day;

    public MyDate(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

/*    public static int com(MyDate m1,MyDate m2){
        int i1 = m1.year - m2.year;
        if (i1 != 0) {
            return i1;
        }
        int i2 = m1.month - m2.month;
        if (i2 != 0) {
            return i2;
        }
        return m1.day - m2.day;
    }*/

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return year + "-" + month + "-" + day;
    }

    @Override
    public int compareTo(MyDate m) {
        int i1 = year - m.year;
        if (i1 != 0) {
            return i1;
        }
        int i2 = month - m.month;
        if (i2 != 0) {
            return i2;
        }
        return day - m.day;
    }
}
